{% extends "pretixcontrol/event/settings_base.html" %}
{% load i18n %}
{% load getitem %}
{% load bootstrap3 %}
{% block inside %}
    <form action="" method="post" class="form-horizontal" enctype="multipart/form-data">
        {% csrf_token %}
        <nav id="event-nav" class="header-nav">
            <div class="navigation">
                <div class="navigation-title">
                    <h1>{% trans "Ticket download" %}</h1>
                </div>
                {% include "pretixcontrol/event/component_link.html" %}
            </div>
        </nav>
        <div class="">
            <fieldset>
                <legend>{% trans "Download settings" %}</legend>
                {% if request.event.settings.ticket_download and not any_enabled %}
                    <div class="alert alert-warning">
                        {% blocktrans trimmed %}
                            You activated ticket downloads but no output provider is enabled. Be sure to enable a plugin and
                            activate an output provider.
                        {% endblocktrans %}
                    </div>
                {% endif %}
                {% bootstrap_form_errors form %}
                {% bootstrap_field form.ticket_download layout="control" horizontal_label_class='sr-only' horizontal_field_class='col-md-12' %}
                {% bootstrap_field form.ticket_download_addons layout="control" horizontal_label_class='sr-only' horizontal_field_class='col-md-12' %}
                {% bootstrap_field form.ticket_download_nonadm layout="control" horizontal_label_class='sr-only' horizontal_field_class='col-md-12' %}
                {% bootstrap_field form.ticket_download_pending layout="control" horizontal_label_class='sr-only' horizontal_field_class='col-md-12' %}
                {% bootstrap_field form.ticket_download_require_validated_email layout="control" horizontal_label_class='sr-only' horizontal_field_class='col-md-12' %}
            </fieldset>
            <fieldset>
                <legend>{% trans "Download formats" %}</legend>
                {% for provider in providers %}
                    <div class="panel panel-default ticketoutput-panel">
                        <div class="panel-heading">
                            <a href="{% url "control:event.settings.tickets.preview" event=request.event.slug organizer=request.organizer.slug output=provider.identifier %}"
                                    class="btn btn-default btn-sm pull-right flip {% if not provider.evaluated_preview_allowed %}disabled{% endif %}"
                                    target="_blank">
                                {% trans "Preview" %}
                            </a>
                            <h3 class="panel-title">
                                {% with 'ticketoutput_'|add:provider.identifier|add:'__enabled' as field_name %}
									{% if field_name in provider.form.fields %}
                                    	{% bootstrap_field provider.form|getitem:field_name layout='inline' label=provider.verbose_name %}
									{% endif %}
                                {% endwith %}
                            </h3>
                            <div class="clear"></div>
                        </div>
                        <div class="panel-body">
                            {% bootstrap_form provider.form exclude='ticketoutput_'|add:provider.identifier|add:'__enabled' layout='horizontal' %}
                            {% with c=provider.settings_content %}
                                {% if c %}{{ c|safe }}{% endif %}
                            {% endwith %}
                        </div>
                    </div>
                {% empty %}
                    <div class="alert alert-warning">
                        {% url "control:event.settings.plugins" event=request.event.slug organizer=request.organizer.slug as plugin_settings_url %}
                        {% blocktrans trimmed with plugin_settings_href='href="'|add:plugin_settings_url|add:'"'|safe %}
                            There are no ticket outputs available. Please go to the
                            <a {{ plugin_settings_href }}>plugin settings</a> and activate one or more ticket output plugins.
                        {% endblocktrans %}
                    </div>
                {% endfor %}
            </fieldset>
            <fieldset>
                <legend>{% trans "Download time" %}</legend>
                {% bootstrap_field form.ticket_download_date layout="control" %}
            </fieldset>
            <fieldset>
                <legend>{% trans "Ticket codes" %}</legend>
                {% bootstrap_field form.ticket_secret_generator layout="control" %}
            </fieldset>
            <fieldset>
                <legend>{% trans "Ticket buying settings" %}</legend>
                {% bootstrap_field form.require_registered_account_for_tickets layout="control" %}
            </fieldset>
        </div>
        <div class="form-group submit-group">
            <button type="submit" class="btn btn-primary btn-save">
                {% trans "Save" %}
            </button>
        </div>
    </form>
{% endblock %}
